package com.apes.hr.paySupport.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.hr.base.model.Job;
import com.apes.hr.base.model.WorkPost;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @Title: SupportApplicationDetail
 * @Description:付费支援申请单(申请支援明细)
 * @author: ZhengZeXian
 * @create: 2021/4/15 10:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SupportApplicationDetail.CONST_TABLE_NAME)
public class SupportApplicationDetail extends BaseModel {

    public static final String CONST_TABLE_NAME = "hr_support_application_detail";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "付费支援申请单支援明细编码", padding = 15)
    @Comment("编码")
    private String  id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "branch_id", referencedColumnName = "id")
    @Comment("申请部门")
    private Branch branch;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "work_post_id", referencedColumnName = "id")
    @Comment("申请岗位")
    private WorkPost workPost;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "job_id", referencedColumnName = "id")
    @Comment("申请职位")
    private Job job;

    @Name
    @Column(name = "apply_qty", nullable = false, columnDefinition = "number(8,0) default 1")
    @Comment("申请人数")
    private int applyQty = 1;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "start_date")
    @Comment("支援开始日期")
    private Date startDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "start_time",referencedColumnName = "id")
    @Comment("支援开始时间")
    private Enumeration startTime; // AM为上午 PM为下午

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "end_date")
    @Comment("支援结束日期")
    private Date endDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "end_time",referencedColumnName = "id")
    @Comment("支援结束时间")
    private Enumeration endTime; // AM为上午 PM为下午

    @Column(name = "support_days", length = 50, nullable = false)
    @Comment("支援天数")
    private String supportDays;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("出人方门店")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "supportApplication_id", referencedColumnName = "id")
    private SupportApplication supportApplication;

}
